package com.lineage.server.timecontroller.pc;

import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.thread.PcOtherThreadPool;
import com.lineage.server.world.WorldIllusionist;
import java.util.Collection;
import java.util.Iterator;
import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class UpdateObjectITimer extends TimerTask {
  private static final Log _log = LogFactory.getLog(UpdateObjectITimer.class);
  
  private ScheduledFuture<?> _timer;
  
  public void start() {
    int timeMillis = 350;
    this._timer = PcOtherThreadPool.get().scheduleAtFixedRate(this, 350L, 350L);
  }
  
  public void run() {
    try {
      Collection<L1PcInstance> allPc = WorldIllusionist.get().all();
      if (allPc.isEmpty())
        return; 
      Iterator<L1PcInstance> iterator = allPc.iterator();
      while (iterator.hasNext()) {
        L1PcInstance tgpc = iterator.next();
        if (UpdateObjectCheck.check(tgpc))
          tgpc.updateObject(); 
      } 
    } catch (Exception e) {
      _log.error("Pc 可见物更新处理时间轴(幻术)异常重启", e);
      PcOtherThreadPool.get().cancel(this._timer, false);
      UpdateObjectITimer objectITimer = new UpdateObjectITimer();
      objectITimer.start();
    } 
  }
}
